package com.bbg.amyam.web.mvc.controller.dto;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.bbg.amyam.domain.model.School;

public class SchoolDTO {

	private String schoolName;
	private String fullName;
	public String getFullName() {
		return fullName;
	}

	public void setFullName(String fullName) {
		this.fullName = fullName;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	private String address;

	public SchoolDTO(School school, String contextPath) {
		if( !StringUtils.isEmpty(school.getLogoURL())){
			this.schoolName="<a href='"+contextPath+"/"+school.getShortName()+"'><img src='"+contextPath+school.getLogoURL()+"' /></a>";
		}else{
			this.schoolName="<a href='"+contextPath+"/"+school.getShortName()+"'>"+school.getFullName()+"</a>";
		}
		this.fullName=school.getFullName();
		String[] addresses={school.getAddress(),school.getCity(),school.getStateCode()==null?"":school.getStateCode().toString(),school.getZipCode()};
		String address=StringUtils.join(addresses," ");
		this.address=address;
	}

	public static List<SchoolDTO> mapping(List<School> schools, String contextPath) {
		ArrayList<SchoolDTO> dtos = new ArrayList<SchoolDTO>();
		if (schools != null) {

			for (School school : schools) {
				SchoolDTO dto = new SchoolDTO(school,contextPath);
				dtos.add(dto);
			}
		}
		return dtos;
	}

	public String getSchoolName() {
		return schoolName;
	}
	
	public void setSchoolName(String schoolName) {
		this.schoolName = schoolName;
	}


}
